package ru.st.selenium.applogic2;

import java.util.List;

import ru.st.selenium.applogic.FilmHelper;
import ru.st.selenium.model.Film;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

	public FilmHelper2(ApplicationManager2 manager) {
		super(manager.getWebDriver());
	}

	@Override
	public void create(Film film) {
		pages.internalPage.ensurePageLoaded().clickAddFilm().ensurePageLoaded()
				.setTitle(film.getTitle()).setYear(film.getYear())
				.clickSaveButton();
	}

	@Override
	public void createWithEmptyFields() {
		pages.internalPage.ensurePageLoaded().clickAddFilm().ensurePageLoaded()
				.clickSaveButton();
	}

	@Override
	public List<String> getFieldsWithErrors() {
		return pages.creationFilmPage.getErrorFields();
	}

	@Override
	public void delete(Film film) {
		pages.mainPage.selectFilm(film);
		pages.filmPage.ensurePageLoaded().removeFilm();
	}

	@Override
	public void deleteByIndex(int index) {
		pages.mainPage.selectFilmByIndex(index);
		pages.filmPage.ensurePageLoaded().removeFilm();
	}

	@Override
	public void search(String title) {
		pages.mainPage.ensurePageLoaded().search(title);
	}
	
	@Override
	public List<Film> searchByPartTitle(String partTitle) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void clearSearch() {
		pages.mainPage.ensurePageLoaded().cleanSearchField();
	}
	
	@Override
	public String getFilmInfo() {
		return pages.filmPage.ensurePageLoaded().getFilmInfo();
	}


	@Override
	public List<Film> getFilms() {
		return pages.mainPage.ensurePageLoaded().getFilms();
	}

	@Override
	public String getTitleFilm() {
		return pages.mainPage.ensurePageLoaded().getTitleFilm();
	}
	
	@Override
	public String getErrorMessage(){
		return pages.mainPage.ensurePageLoaded().getErrorMessage();
	}
}
